﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace YWJiXiao.App.WebForm.AdminManage.Pages
{
    public partial class cache : BaseAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnClearAllCache.Click += new EventHandler(btnClearAllCache_Click);
        }

        void btnClearAllCache_Click(object sender, EventArgs e)
        {
            string key = tbCacheKey.Text;
            List<string> keys = new List<string>();
            IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator();
            while (enumerator.MoveNext())
            {
                keys.Add(enumerator.Key.ToString());
            }
            if (key == "*")
            {
                for (int i = 0; i < keys.Count; i++)
                {
                    HttpRuntime.Cache.Remove(keys[i]);
                }
            }
            else
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Key.ToString().ToLower().StartsWith(tbCacheKey.Text.ToLower()))
                        keys.Add(enumerator.Key.ToString());
                }
                for (int i = 0; i < keys.Count; i++)
                {
                    HttpRuntime.Cache.Remove(keys[i]);
                }
            }
            Page.ClientScript.RegisterStartupScript(this.GetType(), "ad", "alert('清除缓存成功！');", true);
        }
    }
}